package com.jee.mql.web;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.StringTokenizer;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jee.mql.business.UserManager;
import com.jee.mql.model.User;
import com.jee.mql.web.actions.UserAction;


public class Controlleur extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	private UserAction userAction;
	
    public Controlleur() {
    	userAction = new UserAction();
    }
    
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String action = request.getRequestURI();
		
		StringTokenizer st = new StringTokenizer(action);
		st.nextToken("/");
		action = st.nextToken(".").substring(1);
		
		// Gestion des utilisateurs
			gUser(action, request, response);
		
		

	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
	
	private void gUser(String action,HttpServletRequest request, HttpServletResponse response) throws IOException{
		if(action.equals("ajouter"))
			userAction.ajouter(request);
		if(action.equals("afficher"))
			userAction.afficher(response);
		if(action.equals("modifier"))
			userAction.modifier(response);
		if(action.equals("supprimer"))
			userAction.supprimer(response);
	}

}
